package org.example.diet_compass.mapper;

import org.apache.ibatis.annotations.Select;
import org.example.diet_compass.domain.OrderItems;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;
import java.util.Map;

/**
* @author 86135
* @description 针对表【order_items(存储订单与商品之间关系的中间表，记录每个订单中包含哪些商品及数量)】的数据库操作Mapper
* @createDate 2025-03-16 11:01:05
* @Entity org.example.diet_compass.domain.OrderItems
*/
public interface OrderItemsMapper extends BaseMapper<OrderItems> {

    @Select("select * from order_items where order_id =" +
            " (select order_id from orders where user_id = #{userId} and orders.state = \"#{state}\")")
    List<OrderItems> getCartByUserIdAndWait(Integer userId, String state);

    @Select("select goods_id from order_items where order_id = #{orderId}")
    List<String> getGoodIdsByOrderId(Integer orderId);
    @Select("select quantity from order_items where order_id = #{orderId} and goods_id = #{goodId}")
    Integer getGoodCountByOrderIdAndGoodId(Integer orderId, String goodId);

    @Select("select count(quantity) from order_items where order_id = #{orderId}")
    int getOrderTotalCount(Integer orderId);

    @Select("select goods_id,quantity from order_items where order_id = #{orderId}")
    List<Map<String,Object>> getGoodIdsAndCountByOrderId(Integer orderId);
}




